package com.example.studentvotesystem.service;

import com.example.studentvotesystem.entity.ScenicSpot;
import com.example.studentvotesystem.mapper.ScenicSpotMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class ScenicSpotService {
    @Autowired
    private ScenicSpotMapper scenicSpotMapper;

    public List<ScenicSpot> getAllSpots() {
        return scenicSpotMapper.selectAll();
    }

    public List<ScenicSpot> getAllSpotsWithVoteCount() {
        return scenicSpotMapper.selectAllWithVoteCount();
    }

    public ScenicSpot getSpotById(Integer id) {
        return scenicSpotMapper.selectById(id);
    }

    @Transactional
    public void addSpot(ScenicSpot scenicSpot) {
        scenicSpotMapper.insert(scenicSpot);
    }

    @Transactional
    public void updateSpot(ScenicSpot scenicSpot) {
        scenicSpotMapper.update(scenicSpot);
    }

    @Transactional
    public void deleteSpot(Integer id) {
        scenicSpotMapper.delete(id);
    }
}
